"""
所有窗口控件类都需要继承 baseComponent
新增窗体控件，需要添加到 /config/ComponentList.json 里面
添加了会找得更快，没有添加的，只要名字没错，也能找到
"""
from PySide6.QtCore import Qt
from qt_material import apply_stylesheet
from TestToolsV2.components.BaseComponent import baseComponent


class mainWindow(baseComponent):
    # 初始化主窗口
    # noinspection PyCompatibility
    def __init__(self, windownName, windownUi):
        super().__init__(windownName, windownUi)
        self.__mainUi = self.get_windownUi()

    # 定义窗口数据初始化
    def InitWindowData(self):
        pass

    def get_SCostsComboBox_text(self) -> str:
        """
        获取兑换消耗 SCostsComboBox 的值\n
        """
        return self.get_comboBox_value("SCostsComboBox")

    def get_SStrRadioButton_value(self) -> bool:
        """
        获取纯文本比对检查 RadioButton 的值\n
        被选中返回true，否则返回false
        """
        return self.get_radioButton_value("SStrRadioButton")

    def get_SDataRadioButton_value(self) -> bool:
        """
        P4,P6规划检查 RadioButton 的值\n
        被选中返回true，否则返回false
        """
        return self.get_radioButton_value("SDataRadioButton")

    def get_SGoDataCheckBox_value(self) -> bool:
        """
        自动弹窗 CheckBox 的值\n
        被选中返回true，否则返回false
        """
        return self.get_checkBox_value("SGoDataCheckBox")

    def set_SExclPathEdit_text(self, text: str):
        """
        设置 SExclPathEdit 路径输入框 文本
        """
        self.set_lineEdit_value("SExclPathEdit", text)

    def get_SExclPathEdit_text(self) -> str:
        """
        获取 SExclPathEdit 路径输入框 文本
        """
        return self.get_lineEdit_value("SExclPathEdit")

    def set_SResourceEdit_html(self, text: str):
        """
        设置 SResourceEdit 规划输入框 html
        """
        self.set_plainEdit_appHtml("SResourceEdit", text)

    def set_SResourceEdit_text(self, text: str):
        """
        设置 SResourceEdit 规划输入框 文本
        """
        self.set_plainEdit_appText("SResourceEdit", text)

    def get_SResourceEdit_text(self) -> str:
        """
        获取 SResourceEdit 规划输入框 文本
        """
        return self.get_plainEdit_value("SResourceEdit")

    def set_STargetEdit_text(self, text: str):
        """
        设置 SResourceEdit 规划输入框 文本
        """
        self.set_plainEdit_appText("STargetEdit", text)

    def set_STargetEdit_html(self, text: str):
        """
        设置 STargetEdit 基础表输入框 html
        """
        self.set_plainEdit_appHtml("STargetEdit", text)

    def get_STargetEdit_text(self) -> str:
        """
        获取 STargetEdit 基础表输入框 文本
        """
        return self.get_plainEdit_value("STargetEdit")

    def set_SDiffTextEdit_html(self, text: str):
        """
        设置 SDiffTextEdit 差异展示框 文本
        """
        self.set_textEdit_html("SDiffTextEdit", text)

    def get_SDiffTextEdit_text(self) -> str:
        """
        获取 SDiffTextEdit 差异展示框 文本
        """
        return self.get_textEdit_value("SDiffTextEdit")

    def set_SRGLabel_text(self, text: str, showType: int = 0):
        """
        设置 SRGLabel 结果展示Label 文本\n
        text:文本内容\n
        showType:展示类型[0为正确，1为错误，2为警告]
        """
        # 修改style的色值可以修改label底部展示的颜色
        if showType == 0:
            # 绿色
            style = 'QLabel{color: rgb(%s);background-color: rgb(%s);}' % (
                "49, 54, 59", "29, 233, 182")
        elif showType == 1:
            # 红色
            style = 'QLabel{color: rgb(%s);background-color: rgb(%s);}' % (
                "255, 255, 255", "70, 119, 255")
        elif showType == 2:
            # 黄色
            style = 'QLabel{color: rgb(%s);background-color: rgb(%s);}' % (
                '30, 39, 46', '254, 211, 48')
        else:
            style = 'QLabel{}'

        self.set_label_value("SRGLabel", style, text)

    def set_winTop(self, isTop: str):
        """
        设置窗口置顶
        """
        try:
            if isTop == "isTop":
                self.__mainUi.setWindowFlags(Qt.WindowStaysOnTopHint)
                self.showWindown()
            else:
                self.__mainUi.setWindowFlags(Qt.Widget)
                self.showWindown()
        except Exception as e:
            print(e)

    def set_panel(self, panelType: str, app):
        """
        设置窗口主题模式
        """
        if panelType == "dark_teal":
            self.__mainUi.setStyleSheet("*{}")
            apply_stylesheet(app, theme='dark_teal.xml')
        elif panelType == "light_blue":
            self.__mainUi.setStyleSheet("*{}")
            apply_stylesheet(app, theme='light_blue.xml')
        elif panelType == "light_blue_white":
            apply_stylesheet(app, theme='light_blue.xml')
            style = "QTabWidget,QWidget,QPlainTextEdit{ background-color: rgb(240, 240, 240) }"
            self.__mainUi.setStyleSheet(style)
